const jwt = require('jsonwebtoken')


const {secret,expires} = require('../config')

// 加密 


function getToken(info) {
    return jwt.sign(info, secret, {
        expiresIn: expires
    })
}


// 解密 

function  verifyToken(token){
     return new Promise((resolve, reject) => {
          jwt.verify(token,secret,(err,data)=>{
             if(err) return resolve({code:0,message:err})
             resolve({code:1,data})
          })
     })
     
}


module.exports = {
    getToken,
    verifyToken
}